/**************************************************************
  > File Name: 1.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月16日 星期三 10时06分47秒
 **************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>

long count = 0;
int loop = 1;

void alrmAction(int s, siginfo_t *infop, void *unused)
{
	if (infop->si_code != SI_KERNEL)
		return ;
	if (count > 100000)
		loop = 0;
}

void alrm_handler(int s)
{
	loop = 0;
}

int main(int argc, char **argv)
{
	struct sigaction sa;
	struct itimerval itv;
/*
	sa.sa_sigaction = alrmAction;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_SIGINFO;
	itv.it_interval.tv_sec = 0;
	itv.it_interval.tv_usec = 1;
	itv.it_value.tv_sec = 0;
	itv.it_value.tv_usec = 1;

	sigaction(SIGALRM, &sa, NULL);

	setitimer(ITIMER_REAL, &itv, NULL);

	while (loop)
	{
		count++;
	}
	printf("%ld\n",count);
*/
	signal(SIGALRM, alrm_handler);
	alarm(1);	
	while (loop)
	{
		count++;
	}
	printf("%ld\n",count);

    exit(0);
}
